import java.util.Date;
import java.util.HashMap;
import java.util.Collection;;

/**Class represents a managing-system for courses at university
 * 
 * @author Kurt Micheli
 * @author Gabriel Rauter
 * @author Max Mulatz
 */
public class CourseManager {
	
	private HashMap<String, Course> courses = null;
	
	public CourseManager() {
		courses = new HashMap<String, Course>();
	}
		
        /**Adds a new course to the overview of all courses available at university.
         * 
         * @param lvanr The numeric description of the course.
         * @param title The name of the course.
         * @param enrollStart   The day from which on Students can enroll into the course
         * @param enrollEnd The day when the period for Students to enroll into the course ends.
         * @param checkOutEnd   The last possible day for Students to leave the course. 
         */
	public void addCourse(String lvanr, String title, Date enrollStart, Date enrollEnd, Date checkOutEnd) {
		Course temp = new Course(lvanr, title, enrollStart, enrollEnd, checkOutEnd); 
		courses.put(temp.getLvanr(), temp);
	}
	
        /**Enrolls a special Student into the specified course if the course is really available at university. Method uses course's method to enroll Students.
         * 
         * @param course The specified course into which a student should be enrolled.
         * @param student   The Student that wants to enroll into the specified course.
         * @return  True if the Student was sucessfully enrolled, false otherwise. 
         */
	public boolean enroll(String course ,Student student) {
		if(courses.containsKey(course)) {
			return courses.get(course).enroll(student);
		} else {
			return false;
		}
	}
	
        /**Checks out a Student of the speciefied course, if the course really exists at university. Method uses the course's method to check out Studetns.
         * 
         * @param course The course from which the Student should be checked out.
         * @param student The Student that wants to be checked out of the specified course.
         * @return True if the Student was sucessfully checked out from the course, false otherwise.
         */
	public boolean checkOut(String course ,Student student) {
		if(courses.containsKey(course)) {
			return courses.get(course).checkOut(student);
		} else {
			return false;
		}
	}
	
        /**Returns an overview of all Students currently enrolled into the course, if the course is really available at university. The method uses the course's overview of Students. 
         * 
         * @param course The special course from which the detailled information is questioned.
         * @return A list of Strings, every line containing detailled information about one of the Students currently enrolled into the course.
         */
	public String getStudents(String course){
		if(courses.containsKey(course)) {
			Student temp[] = new Student[courses.get(course).getStudents().size()];
			Collection<Student> a = courses.get(course).getStudents().values();
			temp = a.toArray(temp);
			String out ="";
			for(int i = 0;i < temp.length;i++) {
				out = out + temp[i]+'\n';
			}
			return out;
		} else {
			return "No Course Found";
		}
		
	}
		
        /**Returns a list of all courses currently available at university and their basic information.
         * 
         * @return A list of Strings, every line containing the basic information about one of the courses currently available at university.
         */
	public String toString() {
		Course temp[] = new Course[courses.size()];
		Collection<Course> a = courses.values();
		temp = a.toArray(temp);
		String out ="";
		for(int i = 0;i < temp.length;i++) {
			out = out + temp[i]+'\n';
		}
		
		return out;
	}
	

}
